# 一个很大的2D矩阵，如果某点的值，由它周围某些点的值决定，
# 例如（i，j）点 的值取当前周围8个点的平均值，如何使用MapReduce来实现
nums = [
    [19, 50, 10, 37, 82, 31],
    [25, 61, 39, 88, 43, 57],
    [10, 10, 28, 32, 45, 92],
    [33, 21, 87, 10, 54, 48],
    [10, 10, 44, 66, 83, 32],
    [75, 53, 49, 10, 11, 92]
    ]

# map
result = {}
row = len(nums)
col = len(nums[0])
for i in range(row):
    for j in range(col):
        if i==0 or i==row-1 or j==0 or j==col-1:
            continue
        result[(i, j)] = [nums[i-1][j-1]]
        result[(i, j)].append(nums[i-1][j])
        result[(i, j)].append(nums[i-1][j+1])
        result[(i, j)].append(nums[i][j-1])
        result[(i, j)].append(nums[i][j+1])
        result[(i, j)].append(nums[i+1][j-1])
        result[(i, j)].append(nums[i+1][j])
        result[(i, j)].append(nums[i+1][j+1])

# reduce
i = 3
j = 4
print(result[(i-1, j-1)],)
print(sum(result[(i-1, j-1)])/len(result[(i-1, j-1)]))